package hng.component;

import hng.constants.Constants;
import hng.dto.OrderDataDTO;
import hng.dto.OrdersDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Component("redisComponent")
public class RedisComponent extends RedisUtils {

    @Resource
    private RedisUtils redisUtils;


    /**
     * 保存图形验证码
     */
    public void saveCaptcha(String key, String code) {
        redisUtils.setex(key, code, Constants.REDIS_KEY_EXPIRES_FIVE_MIN);
    }

    /**
     * 保存短信验证码
     */
    public void savePhoneCode(String key, String code) {
        redisUtils.setex(key, code, Constants.REDIS_KEY_EXPIRES_FIVE_MIN);
    }

    /**
     * 保存用户订单信息
     */
    public void saveOrders(String key, OrderDataDTO orderDataDTO) {
        redisUtils.setex(key, orderDataDTO, Constants.REDIS_KEY_EXPIRES_FIVE_MIN * 3);
    }
}
